local skel = fk.CreateSkill{
  name = "lb__yaoyue",
}

Fk:loadTranslationTable{
  ["lb__yaoyue"] = "耀跃",
  --[":lb__yaoyue"] = "出牌阶段开始时，你可以失去至多3点体力，令你本回合的【杀】可额外指定等量目标，若指定目标数小于失去体力数，此【杀】的结算次数改至余量数。结束阶段，你将体力回复至你上个出牌阶段造成的伤害数。",

  [":lb__yaoyue"] = "摸牌阶段结束时，你可以失去至多3点体力，然后本回合若你每个阶段使用的首张基本牌为【杀】，此【杀】可额外指定等量目标，若额外指定目标数小于失去体力数，此【杀】的结算次数改至余量数。结束阶段，你将体力回复至你上个出牌阶段造成的伤害数。",

  ["#lb__yaoyue"] = "耀跃：你可以失去至多3点体力，强化你本回合的【杀】",
  ["@lb__yaoyue-turn"] = "耀跃",

  ["$lb__yaoyue1"] = "云吟御水。",
  ["$lb__yaoyue2"] = "天洪奔涌。",
  ["$lb__yaoyue3"] = "霄龙现影，破！",
  ["$lb__yaoyue4"] = "神蛟腾云，起！",
}
--[[
skel:addEffect(fk.EventPhaseStart, {
  anim_type = "masochism",
  audio_index = {1, 2},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(skel.name) and target == player and data.phase == Player.Play
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local n = room:askToNumber(player, {
      min = 1,
      max = 3,
      skill_name = skel.name,
      cancelable = true,
      prompt = "#lb__yaoyue",
    })
    if n then
      event:setCostData(self, {num = n})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local num = event:getCostData(self).num
    room:loseHp(player, num, skel.name)
    room:addPlayerMark(player, "@lb__yaoyue-turn", num)
    room:setPlayerMark(player, "lb__yaoyue-phase", num)
  end,
})
--]]
skel:addEffect(fk.EventPhaseEnd, {
  anim_type = "masochism",
  audio_index = {1, 2},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(skel.name) and target == player and data.phase == Player.Draw
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local n = room:askToNumber(player, {
      min = 1,
      max = 3,
      skill_name = skel.name,
      cancelable = true,
      prompt = "#lb__yaoyue",
    })
    if n then
      event:setCostData(self, {num = n})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local num = event:getCostData(self).num
    room:loseHp(player, num, skel.name)
    room:addPlayerMark(player, "@lb__yaoyue-turn", num)
  end,
})

skel:addEffect(fk.CardUsing, {
  mute = true,
  is_delay_effect = true,
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(skel.name) and target == player and data.card.trueName == "slash" then
      local use_events = player.room.logic:getEventsOfScope(GameEvent.UseCard, 1, function (e)
        --return e.data.from == player and e.data.card.trueName == "slash"
        return e.data.from == player and e.data.card.type == Card.TypeBasic
      end, Player.HistoryPhase)
      return #use_events == 1 and use_events[1].data == data
    end
  end,
  on_use = function(self, event, target, player, data)
    local mark = player:getMark("@lb__yaoyue-turn")
    if mark > 1 then
      player.room:notifySkillInvoked(player, skel.name, "offensive")
      player:broadcastSkillInvoke(skel.name, mark + 1)
    end
    if (mark - #data.tos) > 0 then
      data.additionalEffect = (data.additionalEffect or 0) + (mark - #data.tos)
    end
  end,
  can_refresh = function (self, event, target, player, data)
    return target == player and data.card.type == Card.TypeBasic
  end,
  on_refresh = function (self, event, target, player, data)
    player.room:setPlayerMark(target, "lb__yaoyue-phase", 1)
  end,
})

skel:addEffect(fk.EventPhaseStart, {
  anim_type = "support",
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(skel.name) and target == player and data.phase == Player.Finish then
      local room = player.room
      local phases = room.logic:getEventsByRule(GameEvent.Phase, 1, function (e)
        local phase = e.data
        return phase.phase == Player.Play and phase.who == player and not phase.skipped
      end, 0)
      if #phases > 0 then
        local play = phases[1]
        local num = 0
        play:searchEvents(GameEvent.Damage, 999, function (e)
          local damage = e.data
          if damage.from and damage.from == player and not damage.prevented then
            num = num + damage.damage
          end
        end)
        local recover = num - player.hp
        if recover > 0 then
          event:setCostData(self, {num = recover})
          return true
        end
      end
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local num = event:getCostData(self).num
    room:recover{
      who = player,
      num = num,
      skillName = skel.name,
      recoverBy = player,
    }
  end,
})

skel:addEffect("targetmod", {
  extra_target_func = function (self, player, skill, card)
    if skill.trueName == "slash_skill" and player:hasSkill(skel.name) and player:getMark("lb__yaoyue-phase") == 0 then
      return player:getMark("@lb__yaoyue-turn")
    end
  end,
})

return skel